package com.xunji.standard.controller;

import com.xunji.standard.common.R;
import com.xunji.standard.service.CaseService;
import com.xunji.standard.vo.req.CaseExportRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: xuqiang_imyours
 * @Date: 2025/7/10 18:03
 * @Description:
 **/
@Slf4j
@Api(tags = "案件导出")
@RestController
@RequestMapping("/exp")
public class CaseExportController {
    @Resource
    private CaseService caseService;

    @PostMapping("/single/info")
    @ApiOperation(value = "筛选数据导出（单选和多选）", notes = "筛选数据导出（单选和多选）")
    public R export(@RequestBody CaseExportRequest request) {
        if (request == null || StringUtils.isEmpty(request.getCaseId()) || request.getExportData() == null || request.getExportData().isEmpty()) {
            return R.failure("参数错误");
        }
        String downloadUrl = caseService.doExport(request);
        if (downloadUrl == null) return R.failure("无数据导出！");
        return R.success(downloadUrl);
    }

    @GetMapping("/file/all/{caseId}")
    @ApiOperation(value = "案件所有文件导出", notes = "案件所有文件导出")
    public R exportFileAll(@PathVariable String caseId) {
        String downloadUrl = caseService.doExportAll(caseId);
        if (downloadUrl == null) return R.failure("无数据导出！");
        return R.success(downloadUrl);
    }
}
